package com.lzs.Service.Impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lzs.DAO.RuralCmsOfficeDAO;
import com.lzs.PO.Area;
import com.lzs.PO.Page;
import com.lzs.PO.RuralCmsOffice;
import com.lzs.Service.RuralCmsOfficeService;

@Service
public class RuralCmsOfficeServiceImpl implements RuralCmsOfficeService {
@Autowired
RuralCmsOfficeDAO ruralcmsofficeDAO;

	public List<RuralCmsOffice> findOffices() {
		List<RuralCmsOffice> ruralcmsofficelist = this.ruralcmsofficeDAO.findOffices();
		return ruralcmsofficelist;
	}

	@Override
	public RuralCmsOffice findRuralCmsOfficeById(String office_id) {
		RuralCmsOffice ruralcmsoffice = this.ruralcmsofficeDAO.findRuralCmsOfficeById(office_id);
		return ruralcmsoffice;
	}

	@Override
	public Page<RuralCmsOffice> findRuralCmsOfficePageList(String keyword, Integer pageSize, Integer pageNum) {
		
		List<RuralCmsOffice> ruralcmsofficelist = this.ruralcmsofficeDAO.findRuralCmsOfficeList(keyword);
		
		int totalRecord = ruralcmsofficelist.size();
		
		Page<RuralCmsOffice> page = new Page<RuralCmsOffice>(pageNum, pageSize, totalRecord);

		int startIndex = page.getStartIndex();

		page.setList(ruralcmsofficeDAO.findRuralCmsOfficePageList(keyword, startIndex, pageSize));
		
		return page;
	}

	@Override
	public Boolean countRuralCmsOfficeByName(String office_name) {
		
		long count = this.ruralcmsofficeDAO.countRuralCmsOfficeByName(office_name);
		
		return count==0;
	}

	@Override
	public void addRuralCmsOffice(Map<String, Object> map) {
		
		this.ruralcmsofficeDAO.addRuralCmsOffice(map);
		
	}

	@Override
	public void updateRuralCmsOffice(Map<String, Object> map) {
		
		this.ruralcmsofficeDAO.updateRuralCmsOffice(map);
		
	}

	@Override
	public void deleteRuralCmsOffice(String office_id) {

      this.ruralcmsofficeDAO.deleteRuralCmsOffice(office_id);
		
	}

}
